GBML manual / Maths

Numbers and text

A map of the two kinds of value almost every game is built from - numbers you calculate with and text you show - and which page covers which.

The two things a game keeps track of

Almost everything in a game is one of two kinds of value.

Text has a technical name, string, short for "a string of characters". This manual uses both words, and they mean the same thing.

The two look alike and are not the same. 10 is a number, and you can add to it. "10" in quotation marks is text: the character 1 followed by the character 0. Adding "10" and "5" gives "105".

Which page

You want toReadThe short version
Do arithmetic, round something, or find the distance between two thingsNumbersThere are two kinds of number, whole and fractional. Which one you have changes what a division gives you.
Show a name, a line of dialogue or a scoreTextText is a row of characters with a length limit you choose. GBML can join, cut, search and change it.

Both pages start from nothing. Read Numbers first if you are not sure which to begin with, because text often has a number inside it, such as a score.

Getting from one to the other

To show a number on the screen you turn it into text, and to do sums on something that is written as text you turn it into a number. Two functions do it:

A quicker way to put a number inside a sentence is a template string: text with a $ in front of the quotes and values in curly brackets, like $"SCORE {score}". The Text page shows how it works.

What is in the Maths section

Beyond the Numbers page, the rest of this section is one page per function. Some round a number, some keep it between two limits, some turn an angle into a direction, and some roll a random number. Each page says what goes in and what comes out. The search box at the top of the manual finds them by name.

See also: NumbersTextstringstring_to_numberVariables, types and scope